package demo6;

import java.util.Arrays;

class Student implements Comparable<Student>{
    public String name;
    public int age;
    public double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        /*if(this.age - o.age > 0) {
            return 1;
        }else if(this.age - o.age == 0) {
            return 0;
        }else {
            return -1;
        }*/
        return this.age - o.age;
    }
}

public class Test {
    public static void main(String[] args) {
        Student[] array = new Student[3];
        array[0] = new Student("zhangsan",12,50.2);
        array[1] = new Student("lisi",52,50);
        array[2] = new Student("wangwu",18,70.5);

        System.out.println("排序前：" + Arrays.toString(array));

        Arrays.sort(array);//这个地方运行之后编译器会报错，因为我们没有指定我们排序的规则
        System.out.println("排序后：" + Arrays.toString(array));
    }

    public static void main1(String[] args) {
        int[] array = {1,3,2,9,6,8};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
}
